package cn.thoughtworks.school;

import cn.thoughtworks.school.services.ProgramDiffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Map;

@RestController
@RequestMapping("/api/diff")
public class ProgramDiffController {
    @Autowired
    private ProgramDiffService programDiffService;

    @PostMapping("programs")
    public ResponseEntity updateProgramNotification(@RequestBody Map data) throws ParseException {
        programDiffService.updateProgramNotification(data);
        return new ResponseEntity(HttpStatus.CREATED);
    }

    @GetMapping("programs/{programId}")
    public ResponseEntity getPrograms(@PathVariable Long programId) {
        return ResponseEntity.ok(programDiffService.getProgramParentsAndChildren(programId));
    }

    @GetMapping("programs/{programId}/history")
    public ResponseEntity getProgramHistory(@PathVariable Long programId) {
        return ResponseEntity.ok(programDiffService.getProgramHistory(programId));
    }
}
